home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
utils
/
log.js
< prev
next >
Wrap
Text File
|
2008-10-05
|
2KB
|
65 lines
/*
* This class implement doTech methods
* used to operate over log file
*/
function doTech_Utility(){
/*
* writeLog(Message Text)
* Write message direct to log file
*/
this.writeLog = function(message){
/* this is the filename */
var file = "Alpha_LogFile.log";
// Date
var objDate = new Date();
// add line return
message = "[ " + objDate.toDateString() + ", " + objDate.toTimeString() + " ] " + message + "\n";
// message = message + "\n";
// get profile directory
var filename = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
filename.append(file);
/* create a stream */
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
/* if file does not exist, create and put header */
if(!filename.exists())
this.writeHeader(filename);
// use 0x02 | 0x10 to open for appending
foStream.init(filename,0x02 | 0x10,0664,0); // write, open.
foStream.write(message,message.length);
foStream.close();
}
/*
* writeHeader(FileName)
* Write header into the log file
*/
this.writeHeader = function(filename){
var headerText = "/*\n************************************************************";
headerText += "\nThis file contain information to internal use to \ndoTech team to testing purpose.\n";
headerText += "\nCreation Date: " + Date().toString();
headerText += "\nversion: 0.1.0";
headerText += "\n************************************************************ \n*/\n";
/* create a stream */
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
// use 0x02 | 0x8 write, create
foStream.init(filename,0x02 | 0x08,0664,0); // write, create.
foStream.write(headerText,headerText.length);
foStream.close();
}
}